package com.seecen.controller;


import com.seecen.pojo.UserAddress;
import com.seecen.service.UserAddressService;
import com.seecen.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userAddress")
@CrossOrigin
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    //查询地址
    @PostMapping("selectAllAddress")
    public Result  selectAllAddress(){
        Result ret = userAddressService.selectAllAddress();
        return ret;
    }

    //根据userid查地址
    @PostMapping("selectByUid")
    public Result selectByUid(@RequestParam Integer userId){
       Result ret = userAddressService.selectByUid(userId);
       return ret;
    }
    //根据地址id查地址
    @PostMapping("selectByid")
    public Result selectByid(@RequestParam Integer id){
        Result ret = userAddressService.selectByid(id);
        return ret;
    }

    //插入地址，新建地址
    @PostMapping("insertAddress")
    public Result  insertAddress(@RequestBody UserAddress userAddress){
        Result ret = userAddressService.insertAddress(userAddress);
        return ret;
    }
    //删除
    @DeleteMapping("deleteAddressById")
    public Result  deleteAddressById(@RequestParam Integer id){
        Result ret = userAddressService.deleteAddress(id);
        return ret;
    }

    //修改
    @PostMapping("updateAddress")
    public Result  updateAddress(@RequestBody UserAddress userAddress){
        Result ret = userAddressService.updateAddress(userAddress);
        return ret;
    }

    //设置默认地址
    @PostMapping("setDefaultAddressById")
    public Result setDefaultAddressById(@RequestParam Integer id){
        Result ret = userAddressService.setDefaultAddressById(id);
        return ret;
    }
}
